<template>
    <div>
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :span="7">
                        <a-form-model-item label="搜索内容">
                            <a-input v-model="queryParam.storeName" placeholder="请输入序号、姓名、手机号后四位、菜品、门店进行搜索" />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="7">
                        <a-form-model-item label="商户">
                            <j-dict-select-tag v-model="queryParam.merchantId"
                                dict-code="HC_MERCHANT,STORE_NAME,ID,DEL_FLAG=0" placeholder="请选择商户"
                                @change="searchQuery" />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="10">
                        <a-form-model-item label="付款时间">
                            <a-date-picker :default-value="getTime(queryParam.timeBegin)"
                                :show-time="{ format: 'HH:mm' }" format="YYYY-MM-DD HH:mm" placeholder="开始时间"
                                @change="(value, dateString) => onChange(value, dateString, 'timeBegin')" />
                            -
                            <a-date-picker :default-value="getTime(queryParam.timeEnd)" :show-time="{ format: 'HH:mm' }"
                                format="YYYY-MM-DD HH:mm" placeholder="结束时间"
                                @change="(value, dateString) => onChange(value, dateString, 'timeEnd')" />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="5">
                        <a-form-model-item label="订单状态">
                            <a-select v-model="queryParam.state" :allowClear="true" @change="searchQuery">
                                <a-select-option value="PAY">已付款</a-select-option>
                                <a-select-option value="COMPLETED">已完成</a-select-option>
                                <a-select-option value="CANCELED">已取消</a-select-option>
                                <a-select-option value="REFUNDING">退款中</a-select-option>
                            </a-select>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="5">
                        <a-form-model-item label="所属公司">
                            <j-dict-select-tag v-model="queryParam.companyId"
                                dict-code="HC_COMPANY_INFO,COMPANY_NAME,ID,DEL_FLAG=0" placeholder="请选择所属公司"
                                @change="searchQuery" />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="6">
                        <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                            <a-button type="primary" @click="searchReset" icon="reload"
                                style="margin-left: 8px">重置</a-button>
                            <!-- <a-button type="primary" @click="$refs.notPayOrderModal.show()" icon="reload" style="margin-left: 8px">未支付订单</a-button> -->
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
            <a-button type="primary" icon="download" @click="handleExportXls('订单')">导出</a-button>
            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"
                :action="importExcelUrl" @change="handleImportExcel">
                <!-- <a-button type="primary" icon="import">导入</a-button> -->
            </a-upload>
            <!-- 高级查询区域 -->
            <!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
            <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
            <!--        <a-menu slot="overlay">-->
            <!--          <a-menu-item key="1" @click="batchDel">-->
            <!--            <a-icon type="delete"/>-->
            <!--            删除-->
            <!--          </a-menu-item>-->
            <!--        </a-menu>-->
            <!--        <a-button style="margin-left: 8px"> 批量操作-->
            <!--          <a-icon type="down"/>-->
            <!--        </a-button>-->
            <!--      </a-dropdown>-->
        </div>

        <!-- table区域-begin -->
        <div>
            <!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
            <!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
            <!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
            <!--      </div>-->

            <a-table ref="table" size="middle" :scroll="{ x: true }" :bordered="false" rowKey="id" :columns="columns"
                :dataSource="dataSource" :pagination="ipagination" :loading="loading"
                :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                class="j-table-force-nowrap" @change="handleTableChange">
                <span slot="action" slot-scope="text, record">
                    <a-popconfirm v-if="record.state == '已下单' || record.state == '已付款'" title="确定取消该订单吗?"
                        @confirm="() => handleCancelOrder(record.id)">
                        <a>取消订单</a>
                    </a-popconfirm>
                </span>
            </a-table>
        </div>

        <hc-order-modal ref="modalForm" @ok="modalFormOk"></hc-order-modal>
        <!-- <NotPayOrderModal ref="notPayOrderModal"></NotPayOrderModal> -->
    </div>
</template>

<script>
import { getAction } from '@api/manage'
import moment from 'moment'

const renderContent = (value, row, index) => {
    const obj = {
        children: value,
        attrs: {},
    }
    if (index === 0) {
        obj.attrs.rowSpan = 2
    }
    return obj
}

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import HcOrderModal from './HcOrderModal'
// import NotPayOrderModal from './modules/notPayOrderModal.vue'

function getDate(time) {
    let year = time.getFullYear()
    let month = time.getMonth() + 1
    let day = time.getDate()
    return { year, month, day }
}

let LastDate = new Date(new Date().getTime() - 1 * 1000 * 60 * 60 * 24)
let lastTime = getDate(LastDate)
let newDate = new Date()
let nowTime = getDate(newDate)
let timeBegin = `${lastTime.year}-${lastTime.month > 9 ? lastTime.month : '0' + lastTime.month}-${lastTime.day > 9 ? lastTime.day : '0' + lastTime.day
    } 17:00`
let timeEnd = `${nowTime.year}-${nowTime.month > 9 ? nowTime.month : '0' + nowTime.month}-${nowTime.day > 9 ? nowTime.day : '0' + nowTime.day
    } 12:00`

export default {
    name: 'HcOrderList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
        HcOrderModal,
        // NotPayOrderModal
    },
    data() {
        return {
            description: '订单管理页面',
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: 'center',
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1
                    },
                },
                {
                    title: '取餐序号',
                    dataIndex: 'pickingSerialNo',
                    align: 'center',
                },
                {
                    title: '地址',
                    align: 'center',
                    dataIndex: 'supplyAddress',
                    // customRender: (value, row, index) => {
                    //   return {
                    //     children: value,
                    //     attrs: {rowSpan: row.rowspan},
                    //   };
                    // }
                },
                {
                    title: '姓名',
                    align: 'center',
                    dataIndex: 'nameTakingMeal',
                    // customRender: (value, row, index) => {
                    //   return {
                    //     children: value,
                    //     attrs: {rowSpan: row.rowspan},
                    //   };
                    // }
                },
                // {
                //     title: '手机',
                //     align: 'center',
                //     dataIndex: 'phoneTakingMeals',
                //     // customRender: (value, row, index) => {
                //     //   return {
                //     //     children: value,
                //     //     attrs: {rowSpan: row.rowspan},
                //     //   };
                //     // }
                // },
                {
                    title: '所属公司',
                    algin: 'center',
                    dataIndex: 'companyName',
                },
                {
                    title: '门店名称',
                    align: 'center',
                    dataIndex: 'storeName',
                    // customRender: (value, row, index) => {
                    //   return {
                    //     children: value,
                    //     attrs: {rowSpan: row.rowspan2},
                    //   };
                    // }
                },
                {
                    title: '菜品名称',
                    align: 'center',
                    dataIndex: 'nameDishes',
                },
                {
                    title: '备注',
                    align: 'center',
                    dataIndex: 'remarks',
                    customRender: (value, row, index) => {
                        return value ? value : '无'
                    }
                },
                // {
                //   title: '份数',
                //   align: "center",
                //   dataIndex: 'commodityQuantity'
                // },
                {
                    title: '合作单价',
                    algin: 'center',
                    dataIndex: 'commodityPrice',
                },
                {
                    title: '消费金额',
                    align: 'center',
                    dataIndex: 'totalPrice',
                    // customRender: (value, row, index) => {
                    //   return {
                    //     children: value,
                    //     attrs: {rowSpan: row.rowspan},
                    //   };
                    // }
                },
                // {
                //     title: '抽佣金额',
                //     algin: 'center',
                //     dataIndex: 'commission',
                // },
                {
                    title: '付款时间',
                    align: 'center',
                    dataIndex: 'createTime',
                    // customRender: (value, row, index) => {
                    //   return {
                    //     children: value,
                    //     attrs: {rowSpan: row.rowspan},
                    //   };
                    // }
                },
                // {
                //     title: '下单累计次数',
                //     align: 'center',
                //     dataIndex: 'orderCount',
                //     // customRender: (value, row, index) => {
                //     //   return {
                //     //     children: value,
                //     //     attrs: {rowSpan: row.rowspan},
                //     //   };
                //     // }
                // },
                {
                    title: '状态',
                    align: 'center',
                    dataIndex: 'state',
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: 'center',
                    width: 147,
                    scopedSlots: { customRender: 'action' },
                    // customRender: (value, row, index) => {
                    //   return {
                    //     // children: <a @click="handleEdit(record)" >取消订单</a>,
                    //     children: this.$createElement(
                    //         'a',
                    //         {
                    //           text: "123",
                    //           on: {
                    //             click: () => {
                    //               this.handleEdit(row)
                    //             }
                    //           },
                    //         },
                    //         ["取消订单"]
                    //     ),
                    //     attrs: {rowSpan: row.rowspan},
                    //   };
                    // }
                },
            ],
            url: {
                list: '/hc/hcCompanyFoodOrder/getPageList',
                delete: '/hc/hcOrder/delete',
                deleteBatch: '/hc/hcOrder/deleteBatch',
                exportXlsUrl: '/hc/hcCompanyFoodOrder/platformExportXls',
                importExcelUrl: 'hc/hcOrderMerchant/importExcel',
            },
            dictOptions: {},
            superFieldList: [],
            queryParam: {
                timeBegin,
                timeEnd,
            },
        }
    },
    created() {
        this.getSuperFieldList()
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
        },
    },
    mounted() { },
    methods: {
        moment,
        getTime(time) {
            return time ? this.moment(time, 'YYYY-MM-DD HH:mm') : null
        },
        async handleCancelOrder(id) {
            this.loading = true
            let that = this
            // let res = await getAction('/hc/hcCompanyFoodOrder/cancelCompanyOrder', { orderNum: id })
            let res = await getAction('/hc/hcCompanyFoodOrder/platformCancelCompanyOrder', { orderNum: id })
            console.log('6666res', res);
            if (res.success) {
                that.loadData()
            } else {
                that.$message.warning(res.message)
            }
            that.loading = false
        },
        onChange(value, dateString, field) {
            this.$set(this.queryParam, field, dateString)
        },
        initDictConfig() { },
        getSuperFieldList() {
            let fieldList = []
            fieldList.push({ type: 'string', value: 'userId', text: '用户ID' })
            fieldList.push({ type: 'string', value: 'state', text: '状态' })
            fieldList.push({ type: 'int', value: 'pickingSerialNo', text: '取餐序号' })
            fieldList.push({ type: 'string', value: 'pickingAddress', text: '取餐地址' })
            fieldList.push({ type: 'number', value: 'totalPrice', text: '总价格' })
            this.superFieldList = fieldList
        },
    },
}
</script>
<style scoped>
@import '~@assets/less/common.less';

/*/deep/ table tbody tr:hover > td {*/
/*  background-color: #ffffff !important*/
/*}*/
</style>